const { request } = require('../../../services/request')
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        groupProcessId: String,
        totalAnswerNum: Number,
        currentNum: Number,
        reAnswer: Boolean,
        switchAnswer: Boolean,
        currentLiketype: {
            type: Number,
            observer: 'likeTypeChange'
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        satisfied: false,
        dissatisfied: false,
    },

    /**
     * 组件的方法列表
     */
    lifetimes: {
        attached() {
            console.log('chat-feedback-attached')
            this.likeTypeChange()
        }
    },
    methods: {
        likeTypeChange() {
            let { satisfied, dissatisfied, currentLiketype } = this.data
            console.log('likeTypeChange feedback', currentLiketype)
            if (currentLiketype != null && currentLiketype != undefined) {
                satisfied = currentLiketype == 1
                dissatisfied = currentLiketype == 2
                this.setData({ satisfied, dissatisfied })
            }
        },
        handelSatisfied() {
            const sat = this.data.satisfied
            if (sat) {
                this.setData({ satisfied: !sat })
            } else {
                this.setData({ satisfied: !sat, dissatisfied: sat })
            }
            this.triggerStatusChange()
        },
        handelDissatisfied() {
            const dissat = this.data.dissatisfied
            if (dissat) {
                this.setData({ dissatisfied: !dissat })
            } else {
                this.setData({ dissatisfied: !dissat, satisfied: dissat })
            }
            this.triggerStatusChange()
        },
        triggerStatusChange() {
            const { satisfied, dissatisfied } = this.data
            const params = {
                groupProcessId: this.data.groupProcessId,
                likeType: satisfied ? 1 : dissatisfied ? 2 : 0,
            }
            this.triggerEvent('feedbackStatusChange', params)
        },
        bindLastAnswer() {
            if (!this.data.currentNum == 0)
                this.triggerEvent('switchAnswerContent', -1)
        },
        bindNextAnswer() {
            this.triggerEvent('switchAnswerContent', 1)
        },
        bindRefresh() {
            this.triggerEvent('reanswer')
        },
        handelCopy() {
            console.log('handle copy :>> ');
            this.triggerEvent('copy')
        }
    },
})